package cpu.footprint.api;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.ex.HttpException;
import org.xutils.http.RequestParams;
import org.xutils.common.Callback.CommonCallback;
import org.xutils.common.Callback.Cancelable;
import org.xutils.x;

import java.io.FileNotFoundException;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/7.
 */

public class AppXUtilDao {
    public AppXUtilDao(){

    }

    /**
     * 登录
     * @param
     */
    public static void  GetLogin(final Handler handler,Map<String,Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_GET_LOGIN);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                System.out.println("----------》》》》jsonSTring=="
                        + result);
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    if (resultCode.equals("111")) {
                        obj = jsonObj.getJSONObject("resultData");
                        handler.obtainMessage(ResultMessage.LOGIN_SUCCESS,
                                obj.toString() + "").sendToTarget();
                    } else
                        handler.obtainMessage(ResultMessage.LOGIN_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    handler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    handler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }
    /**
     * 注册
     * @param
     */
    public static void  GetRegist(final Handler handler,Map<String,Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_GET_REGIST);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().get(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                System.out.println("----------》》》》jsonSTring=="
                        + result);
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    if (resultCode.equals("111")) {
                        obj = jsonObj.getJSONObject("resultData");
                        handler.obtainMessage(ResultMessage.REGIST_SUCCESS,
                                obj.toString() + "").sendToTarget();
                    } else
                        handler.obtainMessage(ResultMessage.REGIST_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }
            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    HttpException httpEx = (HttpException) throwable;
                    int responseCode = httpEx.getCode();
                    String responseMsg = httpEx.getMessage();
                    String errorResult = httpEx.getResult();
                    handler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    handler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }
            @Override
            public void onCancelled(CancelledException e) {
            }
            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }
    /**
     * 获取头像
     * @param
     */
    public static void  GetHead(final Handler handler,String ImagUrl,String filepath) {
        RequestParams params=new RequestParams(ImagUrl);
        //设置断点续传
        params.setAutoResume(true);
        params.setSaveFilePath(filepath);
        x.http().post(params,new MyCallBack<byte[]>(){
            @Override
            public void onSuccess(byte[] result) {
                handler.obtainMessage(ResultMessage.GET_HEAD_SUCCESS,result).sendToTarget();
            }
            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    HttpException httpEx = (HttpException) throwable;
                    int responseCode = httpEx.getCode();
                    String responseMsg = httpEx.getMessage();
                    String errorResult = httpEx.getResult();
                    handler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    handler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }

            @Override
            public void onCancelled(CancelledException e) {

            }
            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }
    /**
     * 更新用户头像
     * @param mHandler
     */
    public void UpdateHeadPic(final  Handler mHandler,Map<String,Object> map) throws FileNotFoundException {
        RequestParams params=new RequestParams(ApiUrl.URL_UPDATE_HEADPIC);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    if (resultCode.equals("111")) {
                        mHandler.obtainMessage(ResultMessage.UPDATE_HEAD_SUCCESS
                               ).sendToTarget();
                    } else
                        mHandler.obtainMessage(ResultMessage.UPDATE_HEAD_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }
            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    HttpException httpEx = (HttpException) throwable;
                    int responseCode = httpEx.getCode();
                    String responseMsg = httpEx.getMessage();
                    String errorResult = httpEx.getResult();
                    mHandler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    mHandler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }
            @Override
            public void onCancelled(CancelledException e) {
            }
            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }

    /**
     * 更新个人信息
     * @param mHandler
     *
     */
    public void UpdateClientInfo(final Handler mHandler,Map<String,Object> map) {
        RequestParams params = new RequestParams(ApiUrl.URL_UPDATE_USERINFO);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                System.out.println("----------jsonString: "
                        + result);
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    if (resultCode.equals("111")) {
                        obj = jsonObj.getJSONObject("resultData");
                        mHandler.obtainMessage(ResultMessage.UPDATE_INFO_SUCCESS,
                                obj.toString() + "").sendToTarget();
                    } else
                        mHandler.obtainMessage(ResultMessage.UPDATE_INFO_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }
            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    HttpException httpEx = (HttpException) throwable;
                    int responseCode = httpEx.getCode();
                    String responseMsg = httpEx.getMessage();
                    String errorResult = httpEx.getResult();
                    mHandler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    mHandler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }
            @Override
            public void onCancelled(CancelledException e) {
            }
            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }

    /**
     * 获取群组
     * @param handler
     * @param map
     */
    public void GetGroup(final Handler handler,Map<String,Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_LIST_GROUP);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){

            @Override
            public void onSuccess(String result) {
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    if (resultCode.equals("111")) {
                        JSONArray jsonArray = jsonObj.getJSONArray("datas");
                        handler.obtainMessage(ResultMessage.GET_GROUPS_SUCCESS,
                                jsonArray.toString() + "").sendToTarget();
                    } else
                        handler.obtainMessage(ResultMessage.GET_GROUPS_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    handler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    handler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }

            @Override
            public void onCancelled(CancelledException e) {
            }

            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }
    public void addChatRecord(final Handler handler,Map<String,Object> map){

    }
    /**
     * 获取群组
     * @param handler
     * @param map
     */
    public void GetGroupById(final Handler handler,Map<String,Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_GET_GROUP);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                JSONObject jsonObj = null;
                boolean success = false;
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    success = jsonObj.getBoolean("success");
                    resultInfo = jsonObj.getString("msg");
                    if (success) {
                        JSONObject dobj = jsonObj.getJSONObject("data");
                        handler.obtainMessage(ResultMessage.GET_GROUP_SUCCESS,dobj.toString()).sendToTarget();
                    } else
                        handler.obtainMessage(ResultMessage.GET_GROUP_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    handler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    handler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }

            @Override
            public void onCancelled(CancelledException e) {
            }

            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }
    /**
     * 更新个人信息
     * @param mHandler
     *
     */
    public void UpdateGroupInfo(final Handler mHandler,Map<String,Object> map) {
        RequestParams params = new RequestParams(ApiUrl.URL_UPDATE_GROUP);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                System.out.println("----------jsonString: "
                        + result);
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    if (resultCode.equals("111")) {
                        obj = jsonObj.getJSONObject("resultData");
                        mHandler.obtainMessage(ResultMessage.UPDATE_GROUP_SUCCESS,
                                obj.toString() + "").sendToTarget();
                    } else
                        mHandler.obtainMessage(ResultMessage.UPDATE_GROUP_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }
            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    HttpException httpEx = (HttpException) throwable;
                    int responseCode = httpEx.getCode();
                    String responseMsg = httpEx.getMessage();
                    String errorResult = httpEx.getResult();
                    mHandler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    mHandler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }
            @Override
            public void onCancelled(CancelledException e) {
            }
            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }
    /**
     * 更新用户头像
     * @param mHandler
     */
    public void UpdateGroupHeadPic(final  Handler mHandler,Map<String,Object> map) throws FileNotFoundException {
        RequestParams params=new RequestParams(ApiUrl.URL_UPDATEHEAD_GROUP);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                System.out.println("----------jsonString: "
                        + result);
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    if (resultCode.equals("111")) {
                        mHandler.obtainMessage(ResultMessage.UPDATE_GROUPHEAD_SUCCESS
                        ).sendToTarget();
                    } else
                        mHandler.obtainMessage(ResultMessage.UPDATE_GROUPHEAD_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }
            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    HttpException httpEx = (HttpException) throwable;
                    int responseCode = httpEx.getCode();
                    String responseMsg = httpEx.getMessage();
                    String errorResult = httpEx.getResult();
                    mHandler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    mHandler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }
            @Override
            public void onCancelled(CancelledException e) {
            }
            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }


    /**
     * 获取群组
     * @param handler
     * @param map
     */
    public void GetActive(final Handler handler,Map<String,Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_LIST_ACTIVE);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){

            @Override
            public void onSuccess(String result) {
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    if (resultCode.equals("111")) {
                        JSONArray jsonArray = jsonObj.getJSONArray("resultDatas");
                        handler.obtainMessage(ResultMessage.GET_ACTIVES_SUCCESS,
                                jsonArray.toString() + "").sendToTarget();
                    } else
                        handler.obtainMessage(ResultMessage.GET_ACTIVES_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    handler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    handler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
    /**
     * 申请加入活动
     * @param handler
     * @param map
     */
    public void JoinActive(final Handler handler,Map<String,Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_JOIN_ACTIVE);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    if (resultCode.equals("111")) {
                        handler.obtainMessage(ResultMessage.JOINACTIVE_SUCCESS).sendToTarget();
                    } else
                        handler.obtainMessage(ResultMessage.JOINACTIVE_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    handler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    handler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }
    /**
     *
     * @param handler
     * @param map
     */
    public void GetActiveDetailById(final Handler handler, Map<String, Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_GET_ACTIVE);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                JSONObject jsonObj = null;
                boolean success = false;
                String resultInfo = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    success = jsonObj.getBoolean("success");
                    resultInfo = jsonObj.getString("info");
                    if (success) {
                        obj = jsonObj.getJSONObject("data");
                        handler.obtainMessage(ResultMessage.GET_ACTIVE_SUCCESS,
                                obj.toString() + "").sendToTarget();
                    } else
                        handler.obtainMessage(ResultMessage.GET_ACTIVE_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    handler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    handler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }

    /**
     * 上传图片
     * @param mHandler
     * @param map
     */
    public void UploadPicture(final Handler mHandler, Map<String, Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_UPLOAD_PICTURE);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        params.setMultipart(true);
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                System.out.println("----------jsonString: "
                        + result);
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                String resultData = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    resultData= jsonObj.getString("resultData");
                    if (resultCode.equals("111")) {
                        mHandler.obtainMessage(ResultMessage.UPLOAD_PICTURE_SUCCESS
                                ,resultData).sendToTarget();
                    } else
                        mHandler.obtainMessage(ResultMessage.UPLOAD_PICTURE_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }
            @Override
            public void onError(Throwable throwable, boolean b) {
                if (throwable instanceof HttpException) { // 网络错误
                    HttpException httpEx = (HttpException) throwable;
                    int responseCode = httpEx.getCode();
                    String responseMsg = httpEx.getMessage();
                    String errorResult = httpEx.getResult();
                    System.out.println("-------->responseCode:"+responseCode);
                    System.out.println("-------->responseMsg:"+responseMsg);
                    System.out.println("-------->errorResult:"+errorResult);
                    mHandler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    mHandler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }
            @Override
            public void onCancelled(CancelledException e) {
            }
            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }

    /**
     * 创建活动
     * @param mHandler
     * @param map
     */
    public void CreateActive(final Handler mHandler, Map<String, Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_CREATE_ACTIVE);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                System.out.println("----------jsonString: "
                        + result);
                JSONObject jsonObj = null;
                String resultCode = "";
                String resultInfo = "";
                String resultData = "";
                JSONObject obj = null;
                try {
                    jsonObj = new JSONObject(result);
                    resultCode = jsonObj.getString("resultCode");
                    resultInfo = jsonObj.getString("resultInfo");
                    resultData= jsonObj.getString("resultData");
                    if (resultCode.equals("111")) {
                        mHandler.obtainMessage(ResultMessage.CREATE_ACTIVBE_SUCCESS
                                ,resultData).sendToTarget();
                    } else
                        mHandler.obtainMessage(ResultMessage.CREATE_ACTIVBE_FAILED,
                                resultInfo).sendToTarget();
                } catch (JSONException e) {
                    e.printStackTrace();
                    System.out.println("---->>>err="
                            + e.getMessage().toString());
                }
            }
            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    HttpException httpEx = (HttpException) throwable;
                    int responseCode = httpEx.getCode();
                    String responseMsg = httpEx.getMessage();
                    String errorResult = httpEx.getResult();
                    mHandler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    mHandler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }
            @Override
            public void onCancelled(CancelledException e) {
            }
            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }

    /**
     * 上传经纬度
     * @param mHandler
     * @param map
     */
    public void UploadTrail(final Handler mHandler, Map<String, Object> map) {
        RequestParams params=new RequestParams(ApiUrl.URL_TRAIL_ADD);
        if(null!=map){
            for(Map.Entry<String, Object> entry : map.entrySet()){
                params.addParameter(entry.getKey(), entry.getValue());
            }
        }
        x.http().post(params,  new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
            }
            @Override
            public void onError(Throwable throwable, boolean b) {
                Toast.makeText(x.app(), throwable.getMessage(), Toast.LENGTH_LONG).show();
                if (throwable instanceof HttpException) { // 网络错误
                    HttpException httpEx = (HttpException) throwable;
                    int responseCode = httpEx.getCode();
                    String responseMsg = httpEx.getMessage();
                    String errorResult = httpEx.getResult();
                    mHandler.obtainMessage(ResultMessage.TIMEOUT).sendToTarget();
                } else { // 其他错误
                    mHandler.obtainMessage(ResultMessage.FAILED).sendToTarget();
                }
            }
            @Override
            public void onCancelled(CancelledException e) {
            }
            @Override
            public void onFinished() {
                System.out.print("--------->>>>完成");
            }
        });
    }
}
